var ROLE_ADD = function(){
	_add(function(){
        $('#list').datagrid('reload');
	});
};
var ROLE_UPDATE = function(id){
	_update(id,function(){
        $('#list').datagrid('reload');
	});
};
var ROLE_DELETE = function(id){
	_delete(id,function(){
		$('#list').datagrid('reload');
	});
};
var addParents = function(ids,jqTree,node){
    var parent = jqTree.tree('getParent',node.target);
    if(parent != null && $.inArray(parent.id,ids) == -1){
    	if($.inArray(parent.id,ids) == -1){
    		ids.push(parent.id);
    	}
        addParents(ids,jqTree,parent);
    }
};
var ROLE_PERM = function(id){
	var box = $("#permissionWin");
	box.show();
	box.dialog({
		href:'perm-page.fg?id='+id,
		width:600,
		height:350,
		modal:true,
		buttons: [{
			text:'确定',
			iconCls:'icon-ok',
			handler:function(){
				var jqTree = $('#permissionTree');
			    var nodes = jqTree.tree('getChecked');
			    var ids = [];
			    for(var i=0; i<nodes.length;i++){
			    	if(nodes[i].text.indexOf('查询') != -1){
			    		addParents(ids,jqTree,nodes[i]);
			    	}
			        ids.push(nodes[i].id);
			    }
			    formSubmit('permissionWin','permForm','update-perm.jx','修改权限',{
			    	id:id,
			    	ids:ids.join(',')
			    });
			}
		},{
			text:'关闭',
			handler:function(){
				$("#permissionWin").dialog('close');
			}
		}]
	});
};
$(function(){
	//筛选
    $("#search").click(function(){
        _search();
    });
	//删除筛选条件
    _delcond(function(){
    	$('#list').datagrid('load',$("#condition").data('params')||{});
    });
});
